package com.geoboard.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.geoboard.ActivityInterface;
import com.geoboard.R;

public class BoardMapFrag extends Fragment{

	/**** Members **************************************************/
	private String TAG = this.getClass().getSimpleName();
	private MapFrag mMap;

	/**** Android Callback Methods *********************************/

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		Log.d(TAG, "onCreateView()");
		return inflater.inflate(R.layout.frag_board_map, container, false);		
	}
	
	@Override
	public void onResume(){
		Log.d(TAG, "onResume");
		super.onResume();		
		
		mMap = ((ActivityInterface)getActivity()).getMapFrag();
		
		mMap.getBoards();
		
		ImageView createBut = (ImageView)getActivity().findViewById(R.id.create_button);
		
		createBut.setOnClickListener(new OnClickListener() {
		    public void onClick(final View createBut) {
		    	createBoard();
		     }
		 });
	}
	
	//gets board name from dialog and allows user to define board dimensions
	private void createBoard() {
		Log.d(TAG, "switching to board creation mode.");
		BoardCreateFrag create_frag = new BoardCreateFrag();
		getActivity().getSupportFragmentManager().beginTransaction()
				.addToBackStack(null)
        		.replace(com.geoboard.R.id.overlay_container, create_frag)
        		.commit();
	}
}
